package com.lap.analysis.file.methods;

import com.lap.analysis.source.entity.FieldInfo;
import com.lap.analysis.source.entity.MethodInfo;
import org.apache.commons.lang3.StringUtils;

import java.util.stream.Collectors;

import static com.lap.analysis.tools.Constants.*;

public class DeleteMethod implements AbstractMethod {

  @Override
  public String execute(MethodInfo methodInfo) {
    StringBuilder result = new StringBuilder(128);

    result.append(TAB2).append(formatter(PERFORM_PRE, "delete", methodInfo.getUri()));

    String parameter =
        methodInfo.getFields().stream()
            .map(FieldInfo::getDataName)
            .collect(Collectors.joining(","));

    if (StringUtils.isNotBlank(parameter)) result.append(", ").append(parameter);

    result.append("))").append(WRAP);
    result.append(TAB6).append(EXPECT_STATUS_IS_OK).append(WRAP);
    result.append(TAB6).append(formatter(EXPECT_JSON, getCode(methodInfo))).append(WRAP);

    return result.toString();
  }
}
